//
//  ShengJingMessageViewController.m
//  JiuKuGospel
//
//  Created by jiukuyinyue on 15-8-20.
//  Copyright (c) 2015年 JiuKuForApp. All rights reserved.
//

#import "ShengJingMessageViewController.h"
#import "ShengJingMessageViewController+LoadData.h"

#import "TheHomeManager.h"
#import "ShengJingViewController.h"
#import "MZDayPickerCell.h"
#import "ShengJingSelectTableViewCell.h"
#import "ShengJingMessaegTableViewCell.h"

//#import "UINavigationController+FDFullscreenPopGesture.h"
#import "ShengJingMessageViewController+LCAVPlay.h"

#import "JKSongsMessStatus.h"
#import "TheHomeManager+Additions.h"
#import "LCBibleTableViewController.h"
#import "LCLrcAnalyzer.h"

#import "ManagerMyNotesViewController.h"
#import "LCHistoryDataManager.h"

//#import "JKMusicTempSaveDownLoadHelper.h"
//#import "JKMusicTempSaveFileDownLoadManager.h"
//#import "JKDataHelper.h"
//#import "Reachability.h"
//#import "ShengJingViewController.h"
//#import "PlaySongBgView.h"
//#import "JKSongsMessStatus.h"
//#import "SearchViewController.h"
//#import "ManagerMyNotesViewController.h"

#define LAYER_YINYING 3.0
@interface ShengJingMessageViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>

@property (nonatomic, assign)BOOL loadNextAF;               //是否请求其他数据

//@property (nonatomic, strong)NSMutableArray * allMessageArr;
//@property (nonatomic, strong)NSMutableArray * oneMessageArr;

//@property (nonatomic, assign)NSInteger tempCount;

@property (nonatomic, strong)UIImageView * animalImageView;

@property (nonatomic, assign)BOOL firstPlayBool;                //首次播放

@property (nonatomic, strong)UIView * settingView;          //圣经设置界面
@property (nonatomic, strong)UISlider * setLiangSlider;     //亮度设置
@property (nonatomic, assign)CGFloat fontSizeTemp;          //字体大小的加减

@property (nonatomic, strong)NSString * fuzhiStr;           //复制到剪贴板的内容
@property (nonatomic, strong)NSString * zhangJieStr;        //记录章节(收藏和笔记用)
@property (nonatomic, strong)NSIndexPath * gaoLiangIndex;   //高亮位置

@property (nonatomic, strong)NSMutableDictionary * managerShengJingDic; //圣经行数多个管理

@end

@implementation ShengJingMessageViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    if (self.nameStr != nil) {
        NSString *str = [NSString stringWithFormat:@"%@",_LCPlayer.playingSong.title];
        str = [str substringWithinBoundsLeft:@"约" right:@"("];
        if ([str containsString:self.nameStr]) {//假如标题相同, 就赋值
            self.tabNameLabel.attributedText = [[NSAttributedString alloc] initWithString:self.nameStr];
        } else if (str != nil){
            self.tabNameLabel.attributedText = [[NSAttributedString alloc] initWithString:str];
        }
    }
    [LCFloatingWindow sharedInstance].hidden = NO;//安装AVPlay
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    
    [TheHomeManager shareTheHomeManager].tempCount = _LCPlayer.selectedIndex;
    #pragma mark -  重置阅读字体大小  -
    [[NSUserDefaults standardUserDefaults] setFloat:14 forKey:@"fontSizeTemp"];
    [[TheHomeManager shareTheHomeManager] saveUserMessages];//保存历史查看
    [self.managerShengJingDic removeAllObjects];
    self.fuzhiStr = @"";
    self.zhangJieStr = @"";
    NSLog(@"圣经章页已销毁");
    [LCFloatingWindow sharedInstance].hidden = YES;//安装AVPlay
    _isHistoryPush = NO;
    _isSearchPush = NO;
}

//- (void)dealloc
//{
//    [[NSNotificationCenter defaultCenter] removeObserver:self];
//}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self creareAVPlay];//安装AVPlay

    self.view.backgroundColor = [UIColor whiteColor];
//    self.fd_interactivePopDisabled = YES;//设置没有右侧滑返回

    [LCFloatingWindow sharedInstance].hidden = NO;//显示播放器bar
    
    self.fontSizeTemp = 0.0;
    
    NSString *string = [[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"id"];
    if (![string isEqualToString:@"1"]) {
        [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[self setupHeader]];
    }else{
        [self setupHeader];
    }

    [self setupUI];
    [self setupSettingUI];

    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
    
    LCBibleTableViewController *bibleTableViewController = [[LCBibleTableViewController alloc] initWithStyle:UITableViewStylePlain];
    _bibleTableViewController = bibleTableViewController;
    __weak typeof(self) weakSelf = self;
    
    bibleTableViewController.collectionBlock = ^{
        [weakSelf didSelectRowAtIndexPath];
    };
    
    
    [self.view addSubview:bibleTableViewController.tableView];
    [bibleTableViewController.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.offset(200);
        make.bottom.offset(-60);
    }]; //添加歌词tableView

    [self initData];
    
    if (_LCPlayer.kstatus == LCMusicPlayerStatusPlaying && [_LCPlayer.playingSong.singerName containsString:@"圣经"]) {
        if ([_LCPlayer.playingSong.title hasPrefix:@"新约"] || [_LCPlayer.playingSong.title hasPrefix:@"旧约"]) {
            [self performSelector:@selector(refreshHeaderTitle) withObject:nil afterDelay:0.2];
        }
        if (_isSearchPush == NO) {//从搜索界面跳进来除外
            if ([TheHomeManager shareTheHomeManager].tempCount <= playlistTest.allSongs.count) {
                @try {
                    if(playlistTest.allSongs.count > 0){
                        JKSongsMessStatus *song = playlistTest.allSongs[[TheHomeManager shareTheHomeManager].tempCount];
                        [bibleTableViewController lrcWordWithID:song];
                    }
                } @catch (NSException *exception) {
                    NSLog(@"%zd",[TheHomeManager shareTheHomeManager].tempCount);
                    NSException *songException = [[NSException alloc] initWithName:[NSString stringWithFormat:@"%zd",[TheHomeManager shareTheHomeManager].tempCount] reason:@"" userInfo:nil];
                    NSLog(@"songException = %@", songException);
//                    [[PgyManager sharedPgyManager] reportException:songException];
//                    [[PgyManager sharedPgyManager] reportException:exception];
                }
            }else{
                JKSongsMessStatus *song = playlistTest.allSongs[0];
                [bibleTableViewController lrcWordWithID:song];
            }
        }else{
            NSInteger num = [[_searchTitle substringWithinBoundsLeft:@"第" right:@"章"] integerValue] -1;
            JKSongsMessStatus *song = playlistTest.allSongs[num];
            [bibleTableViewController lrcWordWithID:song];
            [_nameBtn setTitle:[_searchTitle substringWithinBoundsLeft:@"约" right:@"("] forState:UIControlStateNormal];
        }
    }else{
        if ([LCHistoryDataManager loadBibleTextTitleData] && _isHistoryPush == NO){
            [self performSelector:@selector(refreshHistoryPlay) withObject:nil afterDelay:0.05];
        }
    }
    if (_isHistoryPush == YES) {//判断是否从历史纪录里跳进来
        if ([LCHistoryDataManager loadBibleTextTitleData]){
            [self performSelector:@selector(refreshHistoryPlay) withObject:nil afterDelay:0.05];
        }
    }

    
}
//当清空历史纪录 或者第一次进入圣经没有纪录是 创建圣经第一个播放
-(void)initData{
    if (![LCHistoryDataManager loadBibleTextTitleData]){
        [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:@"1"];
        LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
        _LCPlayer.songs = playlistTest.allSongs;
        if (_LCPlayer.songs != nil) {
            [_LCPlayer playAtIndex:0 isSelectPlay:YES];
        }
    }
}

-(void)refreshHistoryPlay{
    [[TheHomeManager shareTheHomeManager] localShengJingSongMessage:[_TheHomeM getSongParentIdWithTitle:[LCHistoryDataManager loadBibleTextTitleData]]];
    self.isShowAlert = NO;
    //圣经播放
    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
    _LCPlayer.songs = playlistTest.allSongs;
    if (_LCPlayer.songs != nil) {
        [_LCPlayer playAtIndex:[[[LCHistoryDataManager loadBibleTextTitleData] substringWithinBoundsLeft:@"第" right:@"章"] integerValue]
         -1 isSelectPlay:YES];
    }
    
}
#pragma mark -  head  -
///刷新头部数据
 -(void)refreshHeaderTitle{
     
     NSString *str = [NSString stringWithFormat:@"%@",_LCPlayer.playingSong.title];
     str = [str substringWithinBoundsLeft:@"约" right:@"("];
     str = [str stringByReplacingOccurrencesOfString:@"新约" withString:@""];
     str = [str stringByReplacingOccurrencesOfString:@"旧约" withString:@""];
     _tabNameLabel.attributedText = [[NSAttributedString alloc] initWithString:str];
     [_nameBtn setTitle:str forState:UIControlStateNormal];
     str = [_LCPlayer.playingSong.title substringWithinBoundsLeft:@"第" right:@"章"];
     _numLabel.text = [NSString stringWithFormat:@"第 %@ 章", str];
     [_countBtn setTitle:str forState:UIControlStateNormal];
 }

///head
-(NSString *)setupHeader{
    //    右设置
    UIView * rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    
    UITapGestureRecognizer * settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingTap)];
    UIView * settingView = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 30, 30)];
    UIImageView * settingImageV = [[UIImageView alloc] initWithFrame:CGRectMake(9, 3, 21, 20)];
    settingImageV.userInteractionEnabled = YES;
    settingImageV.image = [UIImage imageNamed:@"header_set"];
    [settingView addSubview:settingImageV];
    [settingView addGestureRecognizer:settingTap];
    [rightView addSubview:settingView];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightView];
    
    NSString * shengjingID = nil;
    NSString * nameStr = nil;
    if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 0) {
        nameStr = [[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"name"];
        shengjingID = [[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"id"];
        
    }
    if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 1) {
        nameStr = [[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"name"];
        shengjingID = [[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"id"];
    }
    
    self.nameStr = nameStr;
    _numLabel.text = [NSString stringWithFormat:@"第 %zd 章", [TheHomeManager shareTheHomeManager].tempCount+1];
    UILabel * nameLabel = (UILabel *)[self.view viewWithTag:7777];
    nameLabel.attributedText = [[NSAttributedString alloc] initWithString:self.nameStr];
    [_nameBtn setTitle:self.nameStr forState:UIControlStateNormal];
    [_countBtn setTitle:[NSString stringWithFormat:@"%zd", [TheHomeManager shareTheHomeManager].tempCount+1] forState:UIControlStateNormal];
    
    UIView * titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 170, 30)];
    titleView.layer.masksToBounds = YES;
    titleView.layer.cornerRadius = 4;
    titleView.layer.borderWidth = 1.1;
    titleView.layer.borderColor = JK_RED_COLOR.CGColor;
    
    self.nameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _nameBtn.frame = CGRectMake(0, 0, titleView.width/5*3, titleView.height);
    _nameBtn.tag = 7778;
    [_nameBtn addTarget:self action:@selector(nameAction:) forControlEvents:UIControlEventTouchUpInside];
    [_nameBtn addTarget:self action:@selector(changeColor1:) forControlEvents:UIControlEventTouchDown];
    [_nameBtn addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpOutside];
    [_nameBtn setTitle:nameStr forState:UIControlStateNormal];
    [_nameBtn setTitleColor:JK_HUISE_COLOR forState:UIControlStateNormal];
    _nameBtn.backgroundColor = JK_RED_COLOR;
    _nameBtn.titleLabel.font = FONT_14;
    [titleView addSubview:_nameBtn];
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(_nameBtn.right, 0, 1, titleView.height)];
    lineView.backgroundColor = JK_HUISE_COLOR;
    [titleView addSubview:lineView];
    
    self.countBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _countBtn.frame = CGRectMake(_nameBtn.right+1, 0, titleView.width/5*2-1, titleView.height);
    _countBtn.tag = 7779;
    [_countBtn setTitle:[NSString stringWithFormat:@"%zd", [TheHomeManager shareTheHomeManager].tempCount+1] forState:UIControlStateNormal];
    [_countBtn setTitleColor:JK_HUISE_COLOR forState:UIControlStateNormal];
//    _countBtn.backgroundColor = JK_RED_COLOR;
    _countBtn.titleLabel.font = FONT_14;
    [_countBtn addTarget:self action:@selector(countAction:) forControlEvents:UIControlEventTouchUpInside];
    [_countBtn addTarget:self action:@selector(changeColor1:) forControlEvents:UIControlEventTouchDown];
    [_countBtn addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpOutside];
    [titleView addSubview:_countBtn];
    self.navigationItem.titleView = titleView;
    return shengjingID;
}

- (void)setupUI
{
    self.zanwuLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, self.view.width, 30)];
    _zanwuLabel.textAlignment = NSTextAlignmentCenter;
    _zanwuLabel.font = FONT_20;
    _zanwuLabel.text = @"为您加载中...";
    _zanwuLabel.textColor = [UIColor grayColor];

    //暂不使用
    for (int i = 0; i < 5; i ++) {
        UIView * tempHeaderView = [[UIView alloc] initWithFrame:CGRectMake(i*(self.view.width/5), 64, self.view.width/5, 85)];
        if (self.view.height == 736) {
            tempHeaderView.frame  = CGRectMake(i*(self.view.width/5), 64, self.view.width/5, 95);
        }
        if (i == 0 || i == 4) {
            tempHeaderView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
        }
        if (i == 1 || i == 3) {
            tempHeaderView.backgroundColor = [UIColor colorWithRed:225/255.0 green:225/255.0 blue:225/255.0 alpha:1.0];
        }
        if (i == 2) {
            tempHeaderView.backgroundColor = [UIColor whiteColor];
            tempHeaderView.frame = CGRectMake(i*(self.view.width/5), 64, self.view.width/5, 85+12);
            tempHeaderView.tag = 999998;
            tempHeaderView.layer.shadowColor = JK_BLACK2_COLOR.CGColor;
            tempHeaderView.layer.shadowOpacity = 0.8;
            tempHeaderView.layer.shadowOffset = CGSizeMake(0, 0);
            tempHeaderView.layer.shadowRadius = LAYER_YINYING;
            if (self.view.height == 736) {
                tempHeaderView.frame = CGRectMake(i*(self.view.width/5), 64, self.view.width/5, 95+12);
            }
        }
    }
    
    UIView * tempView = [self.view viewWithTag:999998];
    [self.view bringSubviewToFront:tempView];
    
    //暂不使用
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.shengjingTab = [[UITableView alloc] initWithFrame:CGRectMake(0, -64, 85, self.view.width)];
    self.shengjingTab.delegate = self;
    self.shengjingTab.dataSource = self;
    self.shengjingTab.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
    self.shengjingTab.transform = CGAffineTransformMakeRotation(-M_PI_2);
    self.shengjingTab.center = CGPointMake(self.view.width/2, 107);
    self.shengjingTab.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.shengjingTab.backgroundColor = [UIColor clearColor];
    self.shengjingTab.showsVerticalScrollIndicator = NO;
    self.shengjingTab.decelerationRate = UIScrollViewDecelerationRateFast;

    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self setupShengjingMessageTaberView];
    
}

-(void)setupShengjingMessageTaberView{
    
    self.shengjingMessageTab = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.width, self.view.height-64-60) style:UITableViewStylePlain];
    _shengjingMessageTab.delegate = self;
    _shengjingMessageTab.dataSource = self;
    _shengjingMessageTab.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_shengjingMessageTab];
    [self.shengjingMessageTab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(64);
        make.left.right.equalTo(self.view);
        make.bottom.offset(- 60);
    }];
    #pragma mark -  headerView _shengjingMessageTab 标题  -
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 140)];
    
    _shengjingMessageTab.scrollEnabled = NO;

    _shengjingMessageTab.tableHeaderView = headerView;
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 0;// 字体的行间距
    
    UILabel * tabNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, self.view.width, 30)];
    _tabNameLabel = tabNameLabel;
    tabNameLabel.tag = 7777;
    tabNameLabel.attributedText = [[NSAttributedString alloc] initWithString:@"圣 经"];//self.nameStr];
    tabNameLabel.textAlignment = NSTextAlignmentCenter;
    tabNameLabel.font = FONT_30;
    [headerView addSubview:tabNameLabel];
    
    
    
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, tabNameLabel.bottom, tabNameLabel.width, 30)];
    _numLabel.text = [NSString stringWithFormat:@"第 %zd 章", [TheHomeManager shareTheHomeManager].tempCount+1];
    _numLabel.textAlignment = NSTextAlignmentCenter;
    _numLabel.font = FONT_16;
    [headerView addSubview:_numLabel];
    
    [self performSelector:@selector(lateChangeLabel) withObject:nil afterDelay:1];

}
- (void)setupSettingUI{
    //51.181.229
    //圣经章节管理界面(新设计需求)
    NSArray * allArr = [NSArray arrayWithObjects:@"复制", @"分享", @"笔记", @"收藏", @"取消", nil];
    UITapGestureRecognizer * sjManagerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sjManagerTap)];
    self.managerShengJingView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height, self.view.width, 60)];
    [_managerShengJingView addGestureRecognizer:sjManagerTap];
    [[[UIApplication sharedApplication].delegate window] addSubview:_managerShengJingView];
    
    for (int i = 0; i < allArr.count; i++) {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(i*_managerShengJingView.width/5, 0, _managerShengJingView.width/5, _managerShengJingView.height)];
        [_managerShengJingView addSubview:view];
        
        view.backgroundColor = [UIColor whiteColor];
       
        UIImageView * tempImage = [[UIImageView alloc] initWithFrame:CGRectMake((view.width-27)/2, 8, 27, 27)];
        tempImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"z%d", i+1]];
        tempImage.userInteractionEnabled = YES;
        [view addSubview:tempImage];
        
        UILabel * tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, tempImage.bottom, view.width, 20)];
        tempLabel.textAlignment = NSTextAlignmentCenter;
        tempLabel.text = [allArr objectAtIndex:i];
        tempLabel.font = FONT_13;
        [view addSubview:tempLabel];

        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, view.width, view.height);
        btn.userInteractionEnabled = YES;
        btn.backgroundColor = [UIColor clearColor];
        btn.tag = 505+i;
//        [btn setTitle:[allArr objectAtIndex:i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(managerBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [btn addTarget:self action:@selector(managerBtnColor1:) forControlEvents:UIControlEventTouchDown];
        [btn addTarget:self action:@selector(managerBtnColor:) forControlEvents:UIControlEventTouchUpOutside];
        [view addSubview:btn];
        
        

        
    }
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _managerShengJingView.width, 2)];
    lineView.backgroundColor = [UIColor colorWithRed:255/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    [_managerShengJingView addSubview:lineView];
    
    //圣经设置界面
    self.settingView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, self.view.width, 150)];
    _settingView.backgroundColor = [JK_HUISE_LINE_COLOR colorWithAlphaComponent:0.95];
    UIView * fontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _settingView.width, _settingView.height/3)];
    UILabel * fontLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, fontView.height)];
    fontLabel.text = @"字体";
    fontLabel.textAlignment = NSTextAlignmentCenter;
    fontLabel.font = FONT_14;
    [fontView addSubview:fontLabel];
    //字体加
    UIButton * fontJianBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fontJianBtn.frame = CGRectMake(fontLabel.right, (fontView.height-25)/2, 100, 25);
    [fontJianBtn setBackgroundImage:[UIImage imageNamed:@"zitixiao"] forState:UIControlStateNormal];
    [fontJianBtn addTarget:self action:@selector(fontJian) forControlEvents:UIControlEventTouchUpInside];
    [fontView addSubview:fontJianBtn];
    //字体减
    UIButton * fontJiaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fontJiaBtn.frame = CGRectMake(fontView.width-130, (fontView.height-25)/2, 100, 25);
    [fontJiaBtn setBackgroundImage:[UIImage imageNamed:@"zitida"] forState:UIControlStateNormal];
    [fontJiaBtn addTarget:self action:@selector(fontJia) forControlEvents:UIControlEventTouchUpInside];
    [fontView addSubview:fontJiaBtn];
    UIView * lineFont = [[UIView alloc] initWithFrame:CGRectMake(0, fontView.height-1, fontView.width, 1)];
    lineFont.backgroundColor = JK_HUISE_COLOR;
    [fontView addSubview:lineFont];
    [_settingView addSubview:fontView];
    
    
    
    //亮度
    UIView * liangduView = [[UIView alloc] initWithFrame:CGRectMake(0, _settingView.height/3, _settingView.width, _settingView.height/3)];
    UILabel * liangduLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, liangduView.height)];
    liangduLabel.text = @"亮度";
    liangduLabel.textAlignment = NSTextAlignmentCenter;
    liangduLabel.font = FONT_14;
    [liangduView addSubview:liangduLabel];
    self.setLiangSlider = [[UISlider alloc] initWithFrame:CGRectMake(liangduLabel.right, (liangduView.height-30)/2, liangduView.width-liangduLabel.right-30, 30)];
    _setLiangSlider.value = [UIScreen mainScreen].brightness;
    _setLiangSlider.minimumTrackTintColor = JK_RED_COLOR;
    [_setLiangSlider addTarget:self action:@selector(changePhoneLiangdu:) forControlEvents:UIControlEventValueChanged];
    [liangduView addSubview:_setLiangSlider];
    UIView * lineLiangdu = [[UIView alloc] initWithFrame:CGRectMake(0, liangduView.height-1, liangduView.width, 1)];
    lineLiangdu.backgroundColor = JK_HUISE_COLOR;
    [liangduView addSubview:lineLiangdu];
    [_settingView addSubview:liangduView];
    
    
    //背景
    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, _settingView.height/3*2, _settingView.width, _settingView.height/3)];
    UILabel * bgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, bgView.height)];
    bgLabel.text = @"背景";
    bgLabel.textAlignment = NSTextAlignmentCenter;
    bgLabel.font = FONT_14;
    [bgView addSubview:bgLabel];
    
    UIButton * bgWhiteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgWhiteBtn.frame = CGRectMake(bgLabel.right, (bgView.height-30)/2, 30, 30);
    bgWhiteBtn.tag = 1401;
    [bgWhiteBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn1"] forState:UIControlStateNormal];
    [bgWhiteBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgWhiteBtn];
    
    UIButton * bgBlueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgBlueBtn.frame = CGRectMake(bgView.width-30-30, (bgView.height-30)/2, 30, 30);
    bgBlueBtn.tag = 1404;
    [bgBlueBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn4"] forState:UIControlStateNormal];
    [bgBlueBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgBlueBtn];

    
    UIButton * bgRedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgRedBtn.frame = CGRectMake((bgBlueBtn.left-bgWhiteBtn.right-2*30)/3+bgWhiteBtn.right, (bgView.height-30)/2, 30, 30);
    bgRedBtn.tag = 1402;
    [bgRedBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn2"] forState:UIControlStateNormal];
    [bgRedBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgRedBtn];
    
    UIButton * bgGreenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bgGreenBtn.frame = CGRectMake((bgBlueBtn.left-bgWhiteBtn.right-2*30)/3+bgRedBtn.right, (bgView.height-30)/2, 30, 30);
    bgGreenBtn.tag = 1403;
    [bgGreenBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn3"] forState:UIControlStateNormal];
    [bgGreenBtn addTarget:self action:@selector(changeBgColor:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:bgGreenBtn];

    UIView * lineBg = [[UIView alloc] initWithFrame:CGRectMake(0, bgView.height-1, bgView.width, 1)];
    lineBg.backgroundColor = JK_HUISE_COLOR;
    [bgView addSubview:lineBg];
    [_settingView addSubview:bgView];
    
    NSLog(@"%zd", [TheHomeManager shareTheHomeManager].btnTempTag);
    
    
    if ([TheHomeManager shareTheHomeManager].btnTempTag == 0) {
        [TheHomeManager shareTheHomeManager].btnTempTag = 1401;
        [bgWhiteBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn01"] forState:UIControlStateNormal];
        _shengjingMessageTab.backgroundColor = [UIColor whiteColor];
    }else{
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1401) {
            [bgWhiteBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn01"] forState:UIControlStateNormal];
            _shengjingMessageTab.backgroundColor = [UIColor whiteColor];
        }
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1402) {
            [bgRedBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn02"] forState:UIControlStateNormal];
            _shengjingMessageTab.backgroundColor = JK_FENRED_COLOR;

        }
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1403) {
            [bgGreenBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn03"] forState:UIControlStateNormal];
            _shengjingMessageTab.backgroundColor = JK_GREEN_COLOR;

        }
        if ([TheHomeManager shareTheHomeManager].btnTempTag == 1404) {
            [bgBlueBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn04"] forState:UIControlStateNormal];
            _shengjingMessageTab.backgroundColor = JK_BLUE_COLOR;

        }

    }
    
    [self.view addSubview:_settingView];
    _settingView.hidden = YES;
}


- (void)lateChangeLabel
{
    self.numBool = YES;
}

//点击选择器 - 圣经名字触发事件
- (void)nameAction:(UIButton *)btn
{
    [btn setTitleColor:JK_HUISE_LINE_COLOR forState:UIControlStateNormal];
    btn.backgroundColor = JK_RED_COLOR;

    ShengJingViewController * shengJVC = [[ShengJingViewController alloc] init];
//    获取本地保存的位置
    NSString * str = [LCHistoryDataManager loadBibleTextTitleData];
    NSString *selectName = [str substringWithinBoundsLeft:@"约" right:@"("];
    NSInteger selectIndex = [[str substringWithinBoundsLeft:@"第" right:@"章"] integerValue];

    shengJVC.selectIndex = 0;
    shengJVC.nameStr = selectName;//给选择器传 标题
    shengJVC.numCount = selectIndex;//给选择器传 第几章节
    [self presentViewController:shengJVC animated:YES completion:nil];
    NSLog(@"更换圣经");
}

- (void)countAction:(UIButton *)btn
{
    [btn setTitleColor:JK_HUISE_LINE_COLOR forState:UIControlStateNormal];
    btn.backgroundColor = RGBColor(228, 83, 77);
    
    NSInteger tempCount = 0;
    if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 0) {
        tempCount = [[[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"count"] integerValue];
        NSLog(@"0 %s",__func__);
    }
    if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 1) {
        tempCount = [[[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"count"] integerValue];
        NSLog(@"1 %s",__func__);
    }

    ShengJingViewController * shengJVC = [[ShengJingViewController alloc] init];
    shengJVC.selectIndex = 1;
    shengJVC.numCount = tempCount;
    shengJVC.nameStr = self.nameStr;
    [self presentViewController:shengJVC animated:YES completion:nil];
    NSLog(@"更换章节");

}

//正常
- (void)changeColor:(UIButton *)btn
{
    [btn setTitleColor:JK_HUISE_LINE_COLOR forState:UIControlStateNormal];
    btn.backgroundColor = JK_RED_COLOR;
}
//高亮
- (void)changeColor1:(UIButton *)btn
{
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.backgroundColor = JK_HUISE_LINE_COLOR;
}
#pragma mark - 圣经管理(复制, 分享, 笔记, 收藏, 高亮)
- (void)managerBtnAction:(UIButton *)btn
{
    
    UIView * view = btn.superview;
    view.backgroundColor = [UIColor whiteColor];

    NSMutableString *string = [NSMutableString string];
    
    for (NSString *str in _bibleTableViewController.selectedData) {
        [string appendString:str];
        [string appendString:@"\n"];
    }
    
    if (btn.tag == 505) {       //复制到剪贴板
        NSLog(@"%@", self.fuzhiStr);
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        NSLog(@"%@", string);
        NSString *pasteboardString = [NSString stringWithFormat:@"%@\n%@",_LCPlayer.playingSong.title,string];
        
        pasteboard.string = pasteboardString;
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode = MBProgressHUDModeText;//枚举类型不同的效果
        hud.label.text=@"复制成功";
        [self performSelector:@selector(hiddenMBAction) withObject:nil afterDelay:1.0];

    }
    
    
    if (btn.tag == 506) {       //分享
        NSLog(@"进行分享");
        NSArray* imageArray = @[[UIImage imageNamed:@"placeholder"]];
        
        [self shareShengJingMessageWithImageArray:imageArray url:_LCPlayer.playingSong.fileUrl title:_LCPlayer.playingSong.title contentMessage:[NSString stringWithFormat:@"%@\n%@",_LCPlayer.playingSong.title,string] type:SSDKContentTypeText];
    }
    
    if (btn.tag == 507) {       //笔记
        if ([[_UserM usercode] isEqualToString:@""]) {
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AccLogin" bundle:nil];
            UIViewController *controller = [sb instantiateInitialViewController];
            [self.navigationController pushViewController:controller animated:YES];
        }else{
            ManagerMyNotesViewController *nagerMyNotesViewController = [[ManagerMyNotesViewController alloc] init];
            nagerMyNotesViewController.shengJingTitle = _LCPlayer.playingSong.title;
            nagerMyNotesViewController.notesContentStr = string;
            nagerMyNotesViewController.shengJingMessageStr = @"";
            [self.navigationController pushViewController:nagerMyNotesViewController animated:YES];
        }
        NSLog(@"做笔记");
    }
    if (btn.tag == 508) {       //收藏
        if ([[_UserM usercode] isEqualToString:@""]) {
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AccLogin" bundle:nil];
            UIViewController *controller = [sb instantiateInitialViewController];
            [self.navigationController pushViewController:controller animated:YES];
        }
        //调用收藏接口
        NSLog(@"进行收藏");
        [self shengJingMessageCollectionWithTitle:_LCPlayer.playingSong.title fuzhiStr:string];
    }
    if (btn.tag == 509) {       //取消高亮
        NSLog(@"取消高亮");
    }
    if (btn.tag >= 505 && btn.tag <= 509) {
        [self.bibleTableViewController.indexPathArr removeAllObjects];
        [self.bibleTableViewController.selectedData removeAllObjects];
    }
    [UIView animateWithDuration:0.5 animations:^{
        self.managerShengJingView.frame = CGRectMake(0, self.view.height, self.view.width, 60);
    } completion:^(BOOL finished) {
    }];
    [self.managerShengJingDic removeAllObjects];
    [_bibleTableViewController.tableView reloadData];
    self.fuzhiStr = @"";
    self.zhangJieStr = @"";
}
//隐藏圣经管理视图
- (void)sjManagerTap{
    [UIView animateWithDuration:0.5 animations:^{
    } completion:^(BOOL finished) {
        
    }];
}

- (void)managerBtnColor:(UIButton *)btn
{
    UIView * view = btn.superview;
    view.backgroundColor = [UIColor whiteColor];
}

- (void)managerBtnColor1:(UIButton *)btn
{
    UIView * view = btn.superview;
    view.backgroundColor = JK_FENRED_COLOR;
}

#pragma mark - 设置
- (void)settingTap
{
    if (_settingView.hidden) {
        [UIView animateWithDuration:0.5 animations:^{
            self.managerShengJingView.frame = CGRectMake(0, self.view.height, self.view.width, 60);
        } completion:^(BOOL finished) {
            
        }];
        [self.managerShengJingDic removeAllObjects];
        self.fuzhiStr = @"";
        self.zhangJieStr = @"";
        [self.shengjingMessageTab reloadData];
        _settingView.hidden = NO;
        _setLiangSlider.value = [UIScreen mainScreen].brightness;
        [self.view bringSubviewToFront:_settingView];
    }else{
        _settingView.hidden = YES;
    }
}

#pragma mark - 字体加减
//字体加
- (void)fontJia
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BIBLETEXTFONT" object:self userInfo:@{@"BIBLETEXTFONT":@(+1)}];
}
//字体减
- (void)fontJian
{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BIBLETEXTFONT" object:self userInfo:@{@"BIBLETEXTFONT":@(-1)}];
}
#pragma mark - 亮度与背景设置
//亮度
- (void)changePhoneLiangdu:(UISlider *)slider
{
    [[UIScreen mainScreen] setBrightness:slider.value];
}

- (void)changeBgColor:(UIButton *)btn
{
    UIButton * oldBtn = (UIButton *)[self.view viewWithTag:[TheHomeManager shareTheHomeManager].btnTempTag];
    if (oldBtn.tag == 1401) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn1"] forState:UIControlStateNormal];
    }
    if (oldBtn.tag == 1402) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn2"] forState:UIControlStateNormal];
    }
    if (oldBtn.tag == 1403) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn3"] forState:UIControlStateNormal];
    }
    if (oldBtn.tag == 1404) {
        [oldBtn setBackgroundImage:[UIImage imageNamed:@"bgBtn4"] forState:UIControlStateNormal];
    }
    
    
    if (btn.tag == 1401) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn01"] forState:UIControlStateNormal];
        _shengjingMessageTab.backgroundColor = [UIColor whiteColor];
        _bibleTableViewController.view.backgroundColor = [UIColor whiteColor];
    }
    if (btn.tag == 1402) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn02"] forState:UIControlStateNormal];
        _shengjingMessageTab.backgroundColor = JK_FENRED_COLOR;
        _bibleTableViewController.view.backgroundColor = JK_FENRED_COLOR;
    }
    if (btn.tag == 1403) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn03"] forState:UIControlStateNormal];
        _shengjingMessageTab.backgroundColor = JK_GREEN_COLOR;
        _bibleTableViewController.view.backgroundColor = JK_GREEN_COLOR;
    }
    if (btn.tag == 1404) {
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtn04"] forState:UIControlStateNormal];
        _shengjingMessageTab.backgroundColor = JK_BLUE_COLOR;
        _bibleTableViewController.view.backgroundColor = JK_BLUE_COLOR;
    }
    
    [TheHomeManager shareTheHomeManager].btnTempTag = btn.tag;
}

//刷新圣经内容
- (void)reloadMessage
{
    //切换时管理圣经内容清空
    [self.managerShengJingDic removeAllObjects];
    self.fuzhiStr = @"";
    self.zhangJieStr = @"";
    [UIView animateWithDuration:0.5 animations:^{
        self.managerShengJingView.frame = CGRectMake(0, self.view.height, self.view.width, 60);
    } completion:^(BOOL finished) {
        
    }];

    
    self.tempCount = [TheHomeManager shareTheHomeManager].tempCount;
    NSString * nameStr = nil;
    NSString * shengjingID = nil;
    if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 0) {
        nameStr = [[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"name"];
        shengjingID = [[[TheHomeManager shareTheHomeManager].dataJiuyueArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"id"];
    }
    if ([TheHomeManager shareTheHomeManager].tempIndexPath.section == 1) {
        nameStr = [[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"name"];
        shengjingID = [[[TheHomeManager shareTheHomeManager].dataXinyeuArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempIndexPath.row] objectForKey:@"id"];
    }
    
    self.nameStr = nameStr;
    _numLabel.text = [NSString stringWithFormat:@"第 %zd 章", [TheHomeManager shareTheHomeManager].tempCount+1];
    UILabel * nameLabel = (UILabel *)[self.view viewWithTag:7777];
    nameLabel.attributedText = [[NSAttributedString alloc] initWithString:self.nameStr];
    [_nameBtn setTitle:self.nameStr forState:UIControlStateNormal];
    [_countBtn setTitle:[NSString stringWithFormat:@"%zd", [TheHomeManager shareTheHomeManager].tempCount+1] forState:UIControlStateNormal];
    
    [self.timeArray removeAllObjects];
    [self.LRCDictionary removeAllObjects];
    
    [self.timeArray addObjectsFromArray:[TheHomeManager shareTheHomeManager].timeArr];
    [self.LRCDictionary setValuesForKeysWithDictionary:[TheHomeManager shareTheHomeManager].dataShengJingLrcDic];
    
    NSLog(@"%@", [TheHomeManager shareTheHomeManager].timeArr);

    NSLog(@"%zd", _timeArray.count);
    
    [self.shengjingMessageTab reloadData];
//    [self.shengjingMessageTab selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
//    [self playMusicWithIndex];
    
    [[TheHomeManager shareTheHomeManager] saveUserMessages];

    if ([TheHomeManager shareTheHomeManager].isPlayShengJ) {
//        self.playVC.songIndex = [TheHomeManager shareTheHomeManager].tempCount;
//        [TheHomeManager shareTheHomeManager].shengjPlayBool = 1;
//        _playVC.localPlayBool = NO;
//        _playVC.listNameStr = self.nameStr;
//        _playVC.songListNameLabel.text = self.nameStr;
//        
//        [self.playVC playMusicWithIndex:[TheHomeManager shareTheHomeManager].tempCount];
    }
    
}

#pragma mark - 刷新UI
- (void)changeShengJingMessage
{
    //cs切换下个章节(未做越界处理)
    NSString * uid = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempCount] objectForKey:@"id"];
    [[TheHomeManager shareTheHomeManager] localShengJingLrc:uid];
    
    self.tempCount = [TheHomeManager shareTheHomeManager].tempCount;
    
    [[TheHomeManager shareTheHomeManager] saveUserMessages];
}
- (void)reloadShengJingTabCell:(NSInteger)lrcPlace
{
    lrcLineNumber = lrcPlace;
    [self.shengjingMessageTab reloadData];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lrcPlace inSection:0];
    [self.shengjingMessageTab selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}



#pragma mark - 改变字体颜色大小
- (void)changeSelectLabel:(NSInteger)row
{
    NSIndexPath * newIndexPath = [NSIndexPath indexPathForRow:row inSection:0];
    ShengJingSelectTableViewCell * selectCell = (ShengJingSelectTableViewCell *)[_shengjingTab cellForRowAtIndexPath:newIndexPath];
    selectCell.numLabel.textColor = JK_RED_COLOR;
    selectCell.tempLabel.textColor = JK_RED_COLOR;
    selectCell.numLabel.font = FONT_32;
    selectCell.tempLabel.font = FONT_18;
    
    if (row == _currentIndex.row) {
        return;
    }
    
    ShengJingSelectTableViewCell * oldCell = (ShengJingSelectTableViewCell *)[_shengjingTab cellForRowAtIndexPath:_currentIndex];
    oldCell.numLabel.textColor = [UIColor grayColor];
    oldCell.tempLabel.textColor = [UIColor grayColor];
    oldCell.numLabel.font = FONT_30;
    oldCell.tempLabel.font = FONT_14;
    
    _currentIndex = newIndexPath;

    
}


#pragma mark - tableview代理

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([tableView isEqual:_shengjingTab]) {
        return _allMessageArr.count*100;
    }
    if ([tableView isEqual:_shengjingMessageTab]) {
        
        return _timeArray.count;
    }
    return 51;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual:_shengjingTab]) {
        return self.view.width/5;
    }
    if ([tableView isEqual:_shengjingMessageTab]) {
        NSString * message = _LRCDictionary[_timeArray[indexPath.row]];
        NSString * newMessage = [NSString stringWithFormat:@"%@", message];

        if (self.view.height == 667 || self.view.height == 736) {
                CGRect labTitleRect = [newMessage boundingRectWithSize:CGSizeMake(self.view.width-30-54, 1000) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:21.0+self.fontSizeTemp] forKey:NSFontAttributeName] context:nil];
                return labTitleRect.size.height+15;

            }else{
                CGRect labTitleRect = [newMessage boundingRectWithSize:CGSizeMake(self.view.width-30-45, 1000) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17.0+self.fontSizeTemp] forKey:NSFontAttributeName] context:nil];
                return labTitleRect.size.height+10;
            }
        }
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([tableView isEqual:_shengjingMessageTab]) {
        static NSString * cellStr = @"messageCell";

        ShengJingMessaegTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
        if (!cell) {
            cell = [[ShengJingMessaegTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellStr];
            cell.width = self.view.width;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;//该表格选中后没有颜色
        cell.backgroundColor = [UIColor clearColor];
        if (_timeArray.count != 0) {
            //刷新圣经词
            NSString * tempSt = [NSString stringWithFormat:@"%zd:%zd",_tempCount+1, indexPath.row+1];
            cell.tempMoreFontSize = self.fontSizeTemp;
                if (indexPath.row == lrcLineNumber) {
                    
                    cell.messageStr = [NSString stringWithFormat:@"%@", _LRCDictionary[_timeArray[indexPath.row]]];
                    cell.numLabel.text = tempSt;
                    if ([TheHomeManager shareTheHomeManager].isPlayShengJ) {
                        cell.messageLabel.textColor = JK_RED_COLOR;
                        cell.numLabel.textColor = JK_RED_COLOR;
                    }
                } else {

                    cell.messageStr = [NSString stringWithFormat:@"%@", _LRCDictionary[_timeArray[indexPath.row]]];
                    cell.numLabel.text = tempSt;
                }

            if (self.view.height == 667 || self.view.height == 736) {
                cell.messageLabel.font = [UIFont systemFontOfSize:20.0+self.fontSizeTemp];
            }else{
                cell.messageLabel.font = [UIFont systemFontOfSize:16.0+self.fontSizeTemp];
            }
            
            //高亮状态
            NSString * uid = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:[TheHomeManager shareTheHomeManager].tempCount] objectForKey:@"id"];
            NSArray * allKeys = [[TheHomeManager shareTheHomeManager].gaoLiangDic allKeys];
            if ([allKeys containsObject:uid]) {
                NSMutableArray * tempArr = [[TheHomeManager shareTheHomeManager].gaoLiangDic objectForKey:uid];
                if ([tempArr containsObject:[NSString stringWithFormat:@"%zd", indexPath.row]]) {
                    cell.allView.backgroundColor = JK_YELLOW_COLOR;
                }
            }
            
      
        }
    
        //管理选择状态
        NSArray * keys = [_managerShengJingDic allKeys];
        if ([keys containsObject:[NSString stringWithFormat:@"%zd",indexPath.row+1]]) {
            cell.backgroundColor = JK_FENRED_COLOR;
        }
    
        
        
        return cell;
    }
    
    return nil;
}
- (void)didSelectRowAtIndexPath{
//     if (newKeys.count == 0) {
//            [UIView animateWithDuration:0.5 animations:^{
//                self.managerShengJingView.frame = CGRectMake(0, self.view.height, self.view.width, 60);
//            } completion:^(BOOL finished) {
//                
//            }];
//        }else{
//            [[LCFloatingWindow sharedInstance] bringSubviewToFront:self.managerShengJingView];
    [[[UIApplication sharedApplication].delegate window] bringSubviewToFront:_managerShengJingView];
    [self.view bringSubviewToFront:self.managerShengJingView];

            [UIView animateWithDuration:0.5 animations:^{
                self.managerShengJingView.alpha = 1;
                self.managerShengJingView.frame = CGRectMake(0, self.view.height-60, self.view.width, 60);
            } completion:^(BOOL finished) {
                
            }];
//        }
        //

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (_bibleTableViewController.selectedData.count == 0) {
            [UIView animateWithDuration:0.5 animations:^{
                self.managerShengJingView.frame = CGRectMake(0, self.view.height, self.view.width, 60);
                self.managerShengJingView.alpha = 0;
            } completion:nil];
        }
    });

        NSLog(@"点击触发点击触发点击触发点击触发点击触发");
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual:_shengjingTab]) {
        [self changeSelectLabel:indexPath.row];
        [self.shengjingTab selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
        _currentIndex = indexPath;
    }
    
    if ([tableView isEqual:_shengjingMessageTab]) {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        ShengJingMessaegTableViewCell * cell = (ShengJingMessaegTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        _settingView.hidden = YES;
        
        NSArray * keys = [self.managerShengJingDic allKeys];
        if ([keys containsObject:[NSString stringWithFormat:@"%zd", indexPath.row+1]]) {
            [self.managerShengJingDic removeObjectForKey:[NSString stringWithFormat:@"%zd", indexPath.row+1]];
            cell.backgroundColor = [UIColor clearColor];
        }else{
            [self.managerShengJingDic setValue:cell.messageLabel.text forKey:[NSString stringWithFormat:@"%zd", indexPath.row+1]];
            cell.backgroundColor = JK_FENRED_COLOR;
        }
        
        NSArray * newKeys = [self.managerShengJingDic allKeys];

        if (newKeys.count == 0) {
            [UIView animateWithDuration:0.5 animations:^{
                self.managerShengJingView.frame = CGRectMake(0, self.view.height, self.view.width, 60);
            } completion:^(BOOL finished) {
                
            }];
        }else{
            [self.view bringSubviewToFront:self.managerShengJingView];
            [UIView animateWithDuration:0.5 animations:^{
                self.managerShengJingView.frame = CGRectMake(0, self.view.height-60, self.view.width, 60);
            } completion:^(BOOL finished) {
                
            }];
        }
        //
        NSLog(@"点击触发点击触发点击触发点击触发点击触发");
    }
}


#pragma mark - 选择器的滚动代理(弃用)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isEqual:_shengjingMessageTab]) {

    }
    
    if ([scrollView isEqual:_shengjingTab]) {
        NSInteger row = (scrollView.contentOffset.y+self.view.width/10)*5/self.view.width + 2;
        [self changeSelectLabel:row];
    }


}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

    if ([scrollView isEqual:_shengjingMessageTab]) {
        NSLog(@"歌词");
    }
    if ([scrollView isEqual:_shengjingTab]) {
        [self.shengjingTab selectRowAtIndexPath:_currentIndex animated:YES scrollPosition:UITableViewScrollPositionMiddle];
        NSLog(@"选择器");
    }

}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if ([scrollView isEqual:_shengjingTab]) {
        [self.shengjingTab selectRowAtIndexPath:_currentIndex animated:YES scrollPosition:UITableViewScrollPositionMiddle];
        NSLog(@"选择器");
    }


}


#pragma mark - 下载处理方法

-(void)finishedDownloadccc
{
//    self.downlingList =[JKMusicTempSaveFileDownLoadManager sharedFilesDownManage].downinglist;
}
//-(void)finishedDownload:(ASIHTTPRequest *)request
//{
//    [self.downlingList removeObject:request];
//}

- (void)aginDown
{
//    ASIHTTPRequest * firstRequest =[[JKMusicTempSaveFileDownLoadManager sharedFilesDownManage].downinglist firstObject];
//    JKMusicTempSaveFileModel *fileInfo1 = (JKMusicTempSaveFileModel *)[firstRequest.userInfo objectForKey:@"File"];
//    [[JKMusicTempSaveFileDownLoadManager sharedFilesDownManage] keepOnNewASINetworkQueueWithGuid:fileInfo1];
}

-(void)ReloadDownLoadingTable
{
//    JKMusicTempSaveFileDownLoadManager *filedownmanage=[JKMusicTempSaveFileDownLoadManager sharedFilesDownManage];
//    self.downlingList=filedownmanage.downinglist;

}

- (void)loadShengJingOneData:(NSString *)idStr
{
    [self.shengjingMessageTab addSubview:self.zanwuLabel];
    
    //    NSString * url = [NSString stringWithFormat:@"%@action=shengjingzhangjie_SongInfo&id=%@", kBaseFuyin, idStr];
    //    NSLog(@"%@", url);
    //    [JKHttpTool getWithURL:url parameters:nil fetchSomeThing:^(NSDictionary *result) {
    //        [_zanwuLabel removeFromSuperview];
    //        [[[TheHomeManager shareTheHomeManager].shengjingNumZDic objectForKey:self.nameStr] setValue:[result objectForKey:@"data"] forKey:idStr];
    //        [[TheHomeManager shareTheHomeManager] saveUserMessages];
    //        [self.oneMessageArr removeAllObjects];
    //        [self.oneMessageArr addObjectsFromArray:[result objectForKey:@"data"]];
    //        if (self.numBool) {
    //            if ((_currentIndex.row+1)%_allMessageArr.count == 0) {
    //                _numLabel.text = [NSString stringWithFormat:@"第 %zd 章", _allMessageArr.count];
    //            }else
    //            _numLabel.text = [NSString stringWithFormat:@"第 %zd 章", ((_currentIndex.row+1)%_allMessageArr.count)];
    //        }
    //        if (isPlaying) {
    //            [self playMusicWithIndex];
    //        }
    //        [self initLRC];
    //
    //    } failure:^{
    //        _zanwuLabel.text = @"网络不好,暂无加载内容";
    //        NSLog(@"error");
    //    }];
    
}

- (void)playLocationMp4Music:(NSString *)file
{
    //    //    JKSongsMessStatus * status = [[JKSongsMessStatus alloc] init];
    //    //    status.songID = file.songID;
    //    //    status.MusicName = file.fileName;
    //    //    status.wma = file.fileURL;
    //    //    status.wma_time = file.mp3time;
    //    //    status.TLrcWord
    //    [TheHomeManager shareTheHomeManager].isPlaying = isPlaying;
    //    [TheHomeManager shareTheHomeManager].playVCShengj = self;
    //    [TheHomeManager shareTheHomeManager].shengjPlayBool = 1;
    //    [TheHomeManager shareTheHomeManager].zjNameStrShengj = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.tempCount] objectForKey:@"singer"];
    //    [TheHomeManager shareTheHomeManager].songNameShengj = [[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.tempCount] objectForKey:@"MusicName"];
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongMess" object:nil];
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongPlayBtn" object:nil];
    //
    //
    //    //    self.tempCount = (_currentIndex.row+1)%_allMessageArr.count;
    //
    //
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongMess" object:nil];
    //
    //    //    _suoPing = YES;
    //    isPlaying = YES;
    //    lrcLineNumber = 0;
    //    self.loadNextAF = YES;
    //    [[AFSoundManager sharedManager].timer invalidate];
    //
    //
    //
    //    [[AFSoundManager sharedManager] startPlayingLocalMp4FileWithNewUrl:file.fileURL andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
    //        if (!error) {
    //            //判断是否请求歌词数据
    //            if (self.loadNextAF) {
    //                self.loadNextAF = NO;
    //            }
    //
    //            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    //            [formatter setDateFormat:@"mm:ss"];
    //
    //            NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
    //            NSString * tempTimeStr = [formatter stringFromDate:elapsedTimeDate];
    //
    //            //            NSLog(@"%@", tempTimeStr);
    //
    //
    //            if ([_timeArray containsObject:tempTimeStr] && isPlaying) {
    //                if (_timeArray.count != 0) {
    //                    NSInteger lrcPlace = [_timeArray indexOfObject:tempTimeStr];
    //                    lrcLineNumber = lrcPlace;
    //                    [self.shengjingMessageTab reloadData];
    //                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lrcPlace inSection:0];
    //                    [self.shengjingMessageTab selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    //                }
    //            }
    //            
    //            
    //            [TheHomeManager shareTheHomeManager].sliderValue = percentage * 0.01;
    //            [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeSongPlayValue" object:nil];
    //            
    //            
    //            //            if (self.suoPing && timeRemaining>0) {
    //            [self setLockScreenNowPlayingInfoSongName:[[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.tempCount] objectForKey:@"title"] singer:[[[TheHomeManager shareTheHomeManager].dataShengJingSongsArr objectAtIndex:self.tempCount] objectForKey:@"name"] zjName:@"" zjImage:@"" duration:timeRemaining];
    //        } else {
    //            
    //        }
    //    }];
    
}


//#pragma mark - 懒加载
//- (NSMutableArray *)allMessageArr
//{
//    if (_allMessageArr == nil) {
//        self.allMessageArr = [NSMutableArray array];
//    }
//    return _allMessageArr;
//}

- (NSMutableArray *)oneMessageArr
{
    if (_oneMessageArr == nil) {
        self.oneMessageArr = [NSMutableArray array];
    }
    return _oneMessageArr;
}

- (NSMutableDictionary *)managerShengJingDic
{
    if (_managerShengJingDic == nil) {
        self.managerShengJingDic = [NSMutableDictionary dictionary];
    }
    return _managerShengJingDic;
}


@end
